import React, { useState, useEffect, Fragment } from 'react'
import "./App.css";
import {withRouter,Route,Switch,Redirect} from 'react-router-dom'
import {db,auth,app} from './utils/cloudbase'
import {connect} from 'react-redux'
import {login,logout } from './redux/actions/userState'
import Welcome from './components/Welcome'
import Home from './components/Home'
function App(props) {
 useEffect(() => {
<<<<<<< HEAD
=======
    // db.collection('books').get().then(res=>{
    //   console.log(res)
    // })
    // app.auth().signInWithEmailAndPassword('1374636431@qq.com','1374636431zzwxyq').then(res=>{
    //   console.log(res)
    //   console.log('成功')
    // })
>>>>>>> 736eaa2195c1b7bca646cbfe9c94a3bf4562f62a
    if(auth.hasLoginState()){
      props.login()
    }else{
      props.logout()
    }
   console.log(props.userState)
    // console.log(props)
  })
  return (
    <div className="background">
       <div className="appBox">
         <Switch>
           {
              props.userState?(
                <Fragment>
<<<<<<< HEAD
                  <Route path="/home" exact component={Home} />
                                <Redirect to="/home" />

                </Fragment>
              ):(
                <Fragment> 
               <Route path="/welcome" component={Welcome} />
                                <Redirect to="/welcome" />

              </Fragment>
              ) 
=======
                  <Route path="/home" component={Home}/>
                  <Route path="/" exact  render={()=>(<Redirect to="/home"/>)}></Route> 
                  {/* <Redirect to="/home"/> */}
                </Fragment>
              ):(
                <Fragment>
                <Route path="/welcome"  component={Welcome} ></Route> 
                <Route path="/" exact render={()=>(<Redirect to="/welcome"/>)}/>
              </Fragment>
              )
>>>>>>> 736eaa2195c1b7bca646cbfe9c94a3bf4562f62a
           }
         </Switch> 
        </div>  
    </div>
  );
}

export default withRouter(connect(state=>({
  userState:state.userState
}),
   {login,logout}
  )(App))
